package io.wdb.wxapp.controller;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import io.wdb.modules.activity.wxapp.entity.HdLotteryActivityEntity;
/**
 * 对外UT测试
 * @author linxu
 *
 */
public class UnitTestController extends HdLotteryController{
	
	// 测试接口
	@RequestMapping(value = "testRandom", method = RequestMethod.POST)
	@ApiOperation(value = "好友抽奖信息", notes = "testRandom")
	@ApiImplicitParams({
			@ApiImplicitParam(name = "lotterySumCount", value = "抽奖次数 100000", dataType = "Long", paramType = "query", required = true),
			@ApiImplicitParam(name = "password", value = "秘钥", dataType = "String", paramType = "query", required = false)

	})
	@ResponseBody
	public List<String> testRandom(int lotterySumCount, String password) {
		if (!"password".equals(password)) {
			return null;
		}
		int lotterySum = lotterySumCount / 100;// 1000;//百分比计算

		Map<String, Object> sql = new HashMap<String, Object>();
		// 根据activityId查询奖品
		sql.put("filterSql", " activity_id = 'lotteryInfo001' and status = 0");
		List<HdLotteryActivityEntity> prizes = hdLotteryActivityService.queryList(sql);

		String firstLotteryRateOldUser = getConfig("firstLotteryRateOldUser");
		String firstLotteryRateNewUser = getConfig("firstLotteryRateNewUser");

		HdLotteryController test = new HdLotteryController();

		List<String> resultStr = new ArrayList<>();
		resultStr.add(">>>>>>>>>>>>>>>老用户第一次抽奖" + lotterySumCount + "次，START<<<<<<<<<<<<");
		int entity1Int = 0;
		int entity2Int = 0;
		int entity3Int = 0;
		int entity4Int = 0;
		int entity5Int = 0;
		int entity6Int = 0;
		int entity7Int = 0;
		int entity8Int = 0;
		for (int i = 0; i < lotterySumCount; i++) {
			if (test.firstPrizeIndex(prizes, firstLotteryRateOldUser) == 1) {
				entity1Int++;
			}
			;
			if (test.firstPrizeIndex(prizes, firstLotteryRateOldUser) == 2) {
				entity2Int++;
			}
			;
			if (test.firstPrizeIndex(prizes, firstLotteryRateOldUser) == 3) {
				entity3Int++;
			}
			;
			if (test.firstPrizeIndex(prizes, firstLotteryRateOldUser) == 4) {
				entity4Int++;
			}
			;
			if (test.firstPrizeIndex(prizes, firstLotteryRateOldUser) == 5) {
				entity5Int++;
			}
			;
			if (test.firstPrizeIndex(prizes, firstLotteryRateOldUser) == 6) {
				entity6Int++;
			}
			;
			if (test.firstPrizeIndex(prizes, firstLotteryRateOldUser) == 7) {
				entity7Int++;
			}
			;
			if (test.firstPrizeIndex(prizes, firstLotteryRateOldUser) == 8) {
				entity8Int++;
			}
			;
		}
		resultStr.add("[位置1月卡免费券]中奖次数:" + entity1Int + ",概率为:" + (entity1Int / lotterySum) + "%");
		resultStr.add("[位置2借阅金10元]中奖次数:" + entity2Int + ",概率为:" + (entity2Int / lotterySum) + "%");
		resultStr.add("[位置3绘本免费券]中奖次数:" + entity3Int + ",概率为:" + (entity3Int / lotterySum) + "%");
		resultStr.add("[位置4继续努力]中奖次数:" + entity4Int + ",概率为:" + (entity4Int / lotterySum) + "%");
		resultStr.add("[位置5月卡免费券]中奖次数:" + entity5Int + ",概率为:" + (entity5Int / lotterySum) + "%");
		resultStr.add("[位置6借阅金5元]中奖次数:" + entity6Int + ",概率为:" + (entity6Int / lotterySum) + "%");
		resultStr.add("[位置7绘本免费券]中奖次数:" + entity7Int + ",概率为:" + (entity7Int / lotterySum) + "%");
		resultStr.add("[位置8年卡免费券]中奖次数:" + entity8Int + ",概率为:" + (entity8Int / lotterySum) + "%");

		resultStr.add("=========合计概率统计=========");
		resultStr.add("三等奖[5元+10元+继续努力]概率:" + ((entity2Int + entity4Int + entity6Int) / lotterySum) + "%");
		resultStr.add("二等奖[月卡券+绘本券]概率:" + ((entity1Int + entity3Int + entity5Int + entity7Int) / lotterySum) + "%");
		resultStr.add("一等奖[年卡券]概率:" + (entity8Int / lotterySum) + "%");
		resultStr.add(">>>>>>>>>>>>>>>老用户第一次抽奖" + lotterySumCount + "次，END<<<<<<<<<<<<");
		resultStr.add("------------------------------------------------------");
		resultStr.add("===============新用户第一次抽奖" + lotterySumCount + "次，START==============");
		entity1Int = 0;
		entity2Int = 0;
		entity3Int = 0;
		entity4Int = 0;
		entity5Int = 0;
		entity6Int = 0;
		entity7Int = 0;
		entity8Int = 0;
		for (int i = 0; i < lotterySumCount; i++) {
			if (test.firstPrizeIndex(prizes, firstLotteryRateNewUser) == 1) {
				entity1Int++;
			}
			;
			if (test.firstPrizeIndex(prizes, firstLotteryRateNewUser) == 2) {
				entity2Int++;
			}
			;
			if (test.firstPrizeIndex(prizes, firstLotteryRateNewUser) == 3) {
				entity3Int++;
			}
			;
			if (test.firstPrizeIndex(prizes, firstLotteryRateNewUser) == 4) {
				entity4Int++;
			}
			;
			if (test.firstPrizeIndex(prizes, firstLotteryRateNewUser) == 5) {
				entity5Int++;
			}
			;
			if (test.firstPrizeIndex(prizes, firstLotteryRateNewUser) == 6) {
				entity6Int++;
			}
			;
			if (test.firstPrizeIndex(prizes, firstLotteryRateNewUser) == 7) {
				entity7Int++;
			}
			;
			if (test.firstPrizeIndex(prizes, firstLotteryRateNewUser) == 8) {
				entity8Int++;
			}
			;
		}
		resultStr.add("[位置1月卡免费券]中奖次数:" + entity1Int + ",概率为:" + (entity1Int / lotterySum) + "%");
		resultStr.add("[位置2借阅金10元]中奖次数:" + entity2Int + ",概率为:" + (entity2Int / lotterySum) + "%");
		resultStr.add("[位置3绘本免费券]中奖次数:" + entity3Int + ",概率为:" + (entity3Int / lotterySum) + "%");
		resultStr.add("[位置4继续努力]中奖次数:" + entity4Int + ",概率为:" + (entity4Int / lotterySum) + "%");
		resultStr.add("[位置5月卡免费券]中奖次数:" + entity5Int + ",概率为:" + (entity5Int / lotterySum) + "%");
		resultStr.add("[位置6借阅金5元]中奖次数:" + entity6Int + ",概率为:" + (entity6Int / lotterySum) + "%");
		resultStr.add("[位置7绘本免费券]中奖次数:" + entity7Int + ",概率为:" + (entity7Int / lotterySum) + "%");
		resultStr.add("[位置8年卡免费券]中奖次数:" + entity8Int + ",概率为:" + (entity8Int / lotterySum) + "%");

		resultStr.add("=========新用户第一次抽奖合计概率统计=========");
		resultStr.add("获得其他优惠券[年卡券+绘本券+5元+10元+继续努力]概率:"
				+ ((entity8Int + entity2Int + entity4Int + entity6Int + entity3Int + entity7Int) / lotterySum) + "%");
		resultStr.add("获得[月卡]概率:" + ((entity5Int + entity1Int) / lotterySum) + "%");
		resultStr.add("===============新用户第一次抽奖" + lotterySumCount + "次，END==============");
		resultStr.add("------------------------------------------------------");
		// 抽奖概率
		resultStr.add(">>>>>>>>>>>>>>>非第一次抽奖" + lotterySumCount + "次 START<<<<<<<<<<<<");
		entity1Int = 0;
		entity2Int = 0;
		entity3Int = 0;
		entity4Int = 0;
		entity5Int = 0;
		entity6Int = 0;
		entity7Int = 0;
		entity8Int = 0;
		prizes = hdLotteryActivityService.queryList(sql);
		// 概率 lotterySum
		for (int i = 0; i < lotterySumCount; i++) {
			if (test.otherPrize(prizes) == 1) {
				entity1Int++;
			}
			;
			if (test.otherPrize(prizes) == 2) {
				entity2Int++;
			}
			;
			if (test.otherPrize(prizes) == 3) {
				entity3Int++;
			}
			;
			if (test.otherPrize(prizes) == 4) {
				entity4Int++;
			}
			;
			if (test.otherPrize(prizes) == 5) {
				entity5Int++;
			}
			;
			if (test.otherPrize(prizes) == 6) {
				entity6Int++;
			}
			;
			if (test.otherPrize(prizes) == 7) {
				entity7Int++;
			}
			;
			if (test.otherPrize(prizes) == 8) {
				entity8Int++;
			}
			;
		}
		resultStr.add("[位置1月卡免费券]中奖次数:" + entity1Int + ",概率为:" + (entity1Int / lotterySum) + "%");
		resultStr.add("[位置2借阅金10元]中奖次数:" + entity2Int + ",概率为:" + (entity2Int / lotterySum) + "%");
		resultStr.add("[位置3绘本免费券]中奖次数:" + entity3Int + ",概率为:" + (entity3Int / lotterySum) + "%");
		resultStr.add("[位置4继续努力]中奖次数:" + entity4Int + ",概率为:" + (entity4Int / lotterySum) + "%");
		resultStr.add("[位置5月卡免费券]中奖次数:" + entity5Int + ",概率为:" + (entity5Int / lotterySum) + "%");
		resultStr.add("[位置6借阅金5元]中奖次数:" + entity6Int + ",概率为:" + (entity6Int / lotterySum) + "%");
		resultStr.add("[位置7绘本免费券]中奖次数:" + entity7Int + ",概率为:" + (entity7Int / lotterySum) + "%");
		resultStr.add("[位置8年卡免费券]中奖次数:" + entity8Int + ",概率为:" + (entity8Int / lotterySum) + "%");

		resultStr.add("=========合计概率统计=========");
		resultStr.add("三等奖[5元+10元+继续努力]概率:" + ((entity2Int + entity4Int + entity6Int) / lotterySum) + "%");
		resultStr.add("二等奖[月卡券+绘本券]概率:" + ((entity1Int + entity3Int + entity5Int + entity7Int) / lotterySum) + "%");
		resultStr.add("一等奖[年卡券]概率:" + (entity8Int / lotterySum) + "%");
		resultStr.add(">>>>>>>>>>>>>>>非第一次抽奖" + lotterySumCount + "次 END<<<<<<<<<<<<");

		return resultStr;
	}

	public static void main(String[] args) {

		int lotterySumCount = 100000;// 抽奖次数
		int lotterySum = 1000;// 百分比计算

		List<HdLotteryActivityEntity> prizes = new ArrayList<HdLotteryActivityEntity>();
		HdLotteryActivityEntity entity1 = new HdLotteryActivityEntity();
		HdLotteryActivityEntity entity2 = new HdLotteryActivityEntity();
		HdLotteryActivityEntity entity3 = new HdLotteryActivityEntity();
		HdLotteryActivityEntity entity4 = new HdLotteryActivityEntity();
		HdLotteryActivityEntity entity5 = new HdLotteryActivityEntity();
		HdLotteryActivityEntity entity6 = new HdLotteryActivityEntity();
		HdLotteryActivityEntity entity7 = new HdLotteryActivityEntity();
		HdLotteryActivityEntity entity8 = new HdLotteryActivityEntity();

		// 位置
		entity1.setLocation(1);
		entity2.setLocation(2);
		entity3.setLocation(3);
		entity4.setLocation(4);
		entity5.setLocation(5);
		entity6.setLocation(6);
		entity7.setLocation(7);
		entity8.setLocation(8);
		// 奖品名
		entity1.setLotteryName("月卡免费券");
		entity2.setLotteryName("借阅金10元");
		entity3.setLotteryName("绘本免费券");
		entity4.setLotteryName("继续努力");
		entity5.setLotteryName("月卡免费券");
		entity6.setLotteryName("借阅金5元");
		entity7.setLotteryName("绘本免费券");
		entity8.setLotteryName("年卡免费券");
		prizes.add(entity1);
		prizes.add(entity2);
		prizes.add(entity3);
		prizes.add(entity4);
		prizes.add(entity5);
		prizes.add(entity6);
		prizes.add(entity7);
		prizes.add(entity8);

		HdLotteryController test = new HdLotteryController();

		String firstLotteryRateOldUser = "0,3000,0,4000,0,3000,0,0";// 老用户第一次抽奖概率设置
		System.out.println(">>>>>>>>>>>>>>>老用户第一次抽奖" + lotterySumCount + "次，START<<<<<<<<<<<<");
		int entity1Int = 0;
		int entity2Int = 0;
		int entity3Int = 0;
		int entity4Int = 0;
		int entity5Int = 0;
		int entity6Int = 0;
		int entity7Int = 0;
		int entity8Int = 0;
		for (int i = 0; i < lotterySumCount; i++) {
			if (test.firstPrizeIndex(prizes, firstLotteryRateOldUser) == 1) {
				entity1Int++;
			}
			;
			if (test.firstPrizeIndex(prizes, firstLotteryRateOldUser) == 2) {
				entity2Int++;
			}
			;
			if (test.firstPrizeIndex(prizes, firstLotteryRateOldUser) == 3) {
				entity3Int++;
			}
			;
			if (test.firstPrizeIndex(prizes, firstLotteryRateOldUser) == 4) {
				entity4Int++;
			}
			;
			if (test.firstPrizeIndex(prizes, firstLotteryRateOldUser) == 5) {
				entity5Int++;
			}
			;
			if (test.firstPrizeIndex(prizes, firstLotteryRateOldUser) == 6) {
				entity6Int++;
			}
			;
			if (test.firstPrizeIndex(prizes, firstLotteryRateOldUser) == 7) {
				entity7Int++;
			}
			;
			if (test.firstPrizeIndex(prizes, firstLotteryRateOldUser) == 8) {
				entity8Int++;
			}
			;
		}
		System.out.println("[位置1月卡免费券]中奖次数:" + entity1Int + ",概率为:" + (entity1Int / lotterySum) + "%");
		System.out.println("[位置2借阅金10元]中奖次数:" + entity2Int + ",概率为:" + (entity2Int / lotterySum) + "%");
		System.out.println("[位置3绘本免费券]中奖次数:" + entity3Int + ",概率为:" + (entity3Int / lotterySum) + "%");
		System.out.println("[位置4继续努力]中奖次数:" + entity4Int + ",概率为:" + (entity4Int / lotterySum) + "%");
		System.out.println("[位置5月卡免费券]中奖次数:" + entity5Int + ",概率为:" + (entity5Int / lotterySum) + "%");
		System.out.println("[位置6借阅金5元]中奖次数:" + entity6Int + ",概率为:" + (entity6Int / lotterySum) + "%");
		System.out.println("[位置7绘本免费券]中奖次数:" + entity7Int + ",概率为:" + (entity7Int / lotterySum) + "%");
		System.out.println("[位置8年卡免费券]中奖次数:" + entity8Int + ",概率为:" + (entity8Int / lotterySum) + "%");

		System.out.println("=========合计概率统计=========");
		System.out.println("三等奖[5元+10元+继续努力]概率:" + ((entity2Int + entity4Int + entity6Int) / lotterySum) + "%");
		System.out
				.println("二等奖[月卡券+绘本券]概率:" + ((entity1Int + entity3Int + entity5Int + entity7Int) / lotterySum) + "%");
		System.out.println("一等奖[年卡券]概率:" + (entity8Int / lotterySum) + "%");
		System.out.println(">>>>>>>>>>>>>>>老用户第一次抽奖" + lotterySumCount + "次，END<<<<<<<<<<<<");
		System.out.println("------------------------------------------------------");
		System.out.println("===============新用户第一次抽奖" + lotterySumCount + "次，START==============");
		String firstLotteryRateNewUser = "3500,500,500,500,3500,500,500,500";// 新用户第一次抽奖概率设置
		entity1Int = 0;
		entity2Int = 0;
		entity3Int = 0;
		entity4Int = 0;
		entity5Int = 0;
		entity6Int = 0;
		entity7Int = 0;
		entity8Int = 0;
		for (int i = 0; i < lotterySumCount; i++) {
			if (test.firstPrizeIndex(prizes, firstLotteryRateNewUser) == 1) {
				entity1Int++;
			}
			;
			if (test.firstPrizeIndex(prizes, firstLotteryRateNewUser) == 2) {
				entity2Int++;
			}
			;
			if (test.firstPrizeIndex(prizes, firstLotteryRateNewUser) == 3) {
				entity3Int++;
			}
			;
			if (test.firstPrizeIndex(prizes, firstLotteryRateNewUser) == 4) {
				entity4Int++;
			}
			;
			if (test.firstPrizeIndex(prizes, firstLotteryRateNewUser) == 5) {
				entity5Int++;
			}
			;
			if (test.firstPrizeIndex(prizes, firstLotteryRateNewUser) == 6) {
				entity6Int++;
			}
			;
			if (test.firstPrizeIndex(prizes, firstLotteryRateNewUser) == 7) {
				entity7Int++;
			}
			;
			if (test.firstPrizeIndex(prizes, firstLotteryRateNewUser) == 8) {
				entity8Int++;
			}
			;
		}
		System.out.println("[位置1月卡免费券]中奖次数:" + entity1Int + ",概率为:" + (entity1Int / lotterySum) + "%");
		System.out.println("[位置2借阅金10元]中奖次数:" + entity2Int + ",概率为:" + (entity2Int / lotterySum) + "%");
		System.out.println("[位置3绘本免费券]中奖次数:" + entity3Int + ",概率为:" + (entity3Int / lotterySum) + "%");
		System.out.println("[位置4继续努力]中奖次数:" + entity4Int + ",概率为:" + (entity4Int / lotterySum) + "%");
		System.out.println("[位置5月卡免费券]中奖次数:" + entity5Int + ",概率为:" + (entity5Int / lotterySum) + "%");
		System.out.println("[位置6借阅金5元]中奖次数:" + entity6Int + ",概率为:" + (entity6Int / lotterySum) + "%");
		System.out.println("[位置7绘本免费券]中奖次数:" + entity7Int + ",概率为:" + (entity7Int / lotterySum) + "%");
		System.out.println("[位置8年卡免费券]中奖次数:" + entity8Int + ",概率为:" + (entity8Int / lotterySum) + "%");

		System.out.println("=========新用户第一次抽奖合计概率统计=========");
		System.out.println("获得其他优惠券[年卡券+绘本券+5元+10元+继续努力]概率:"
				+ ((entity8Int + entity2Int + entity4Int + entity6Int + entity3Int + entity7Int) / lotterySum) + "%");
		System.out.println("获得[月卡]概率:" + ((entity5Int + entity1Int) / lotterySum) + "%");
		System.out.println("===============新用户第一次抽奖" + lotterySumCount + "次，END==============");
		System.out.println("------------------------------------------------------");
		// 抽奖概率
		System.out.println(">>>>>>>>>>>>>>>非第一次抽奖" + lotterySumCount + "次 START<<<<<<<<<<<<");
		entity1Int = 0;
		entity2Int = 0;
		entity3Int = 0;
		entity4Int = 0;
		entity5Int = 0;
		entity6Int = 0;
		entity7Int = 0;
		entity8Int = 0;

		// 概率 lotterySum
		entity1.setLotteryRate(75);
		entity2.setLotteryRate(200);
		entity3.setLotteryRate(75);
		entity4.setLotteryRate(200);
		entity5.setLotteryRate(75);
		entity6.setLotteryRate(200);
		entity7.setLotteryRate(75);
		entity8.setLotteryRate(100);

		for (int i = 0; i < lotterySumCount; i++) {
			if (test.otherPrize(prizes) == 1) {
				entity1Int++;
			}
			;
			if (test.otherPrize(prizes) == 2) {
				entity2Int++;
			}
			;
			if (test.otherPrize(prizes) == 3) {
				entity3Int++;
			}
			;
			if (test.otherPrize(prizes) == 4) {
				entity4Int++;
			}
			;
			if (test.otherPrize(prizes) == 5) {
				entity5Int++;
			}
			;
			if (test.otherPrize(prizes) == 6) {
				entity6Int++;
			}
			;
			if (test.otherPrize(prizes) == 7) {
				entity7Int++;
			}
			;
			if (test.otherPrize(prizes) == 8) {
				entity8Int++;
			}
			;
		}
		System.out.println("[位置1月卡免费券]中奖次数:" + entity1Int + ",概率为:" + (entity1Int / lotterySum) + "%");
		System.out.println("[位置2借阅金10元]中奖次数:" + entity2Int + ",概率为:" + (entity2Int / lotterySum) + "%");
		System.out.println("[位置3绘本免费券]中奖次数:" + entity3Int + ",概率为:" + (entity3Int / lotterySum) + "%");
		System.out.println("[位置4继续努力]中奖次数:" + entity4Int + ",概率为:" + (entity4Int / lotterySum) + "%");
		System.out.println("[位置5月卡免费券]中奖次数:" + entity5Int + ",概率为:" + (entity5Int / lotterySum) + "%");
		System.out.println("[位置6借阅金5元]中奖次数:" + entity6Int + ",概率为:" + (entity6Int / lotterySum) + "%");
		System.out.println("[位置7绘本免费券]中奖次数:" + entity7Int + ",概率为:" + (entity7Int / lotterySum) + "%");
		System.out.println("[位置8年卡免费券]中奖次数:" + entity8Int + ",概率为:" + (entity8Int / lotterySum) + "%");

		System.out.println("=========合计概率统计=========");
		System.out.println("三等奖[5元+10元+继续努力]概率:" + ((entity2Int + entity4Int + entity6Int) / lotterySum) + "%");
		System.out
				.println("二等奖[月卡券+绘本券]概率:" + ((entity1Int + entity3Int + entity5Int + entity7Int) / lotterySum) + "%");
		System.out.println("一等奖[年卡券]概率:" + (entity8Int / lotterySum) + "%");
		System.out.println(">>>>>>>>>>>>>>>非第一次抽奖" + lotterySumCount + "次 END<<<<<<<<<<<<");

	}

}
